package onetomanymapping;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.engine.Cascade;

@Entity
@Table(name="Autors")
public class Autor {
	@Id
	private int autor_id;

	private String autor_name;
	
	// bidirectional
	@OneToMany (cascade=CascadeType.ALL,mappedBy="author",fetch=FetchType.EAGER)
	private Set<Book> books;
	
	@Transient // this field willn't be persisted , and willn't be requested from db
	private String autor_name_and_id_concatenated;
	
	
	public String getAutor_name_and_id_concatenated() {
		this.autor_name_and_id_concatenated=this.autor_id+" "+this.autor_name;
		return this.autor_name_and_id_concatenated;
	}

	public String getAutor_name() {
		return autor_name;
	}

	public void setAutor_name(String autor_name) {
		this.autor_name = autor_name;
	}

	public int getAutor_id() {
		return autor_id;
	}

	public void setAutor_id(int autor_id) {
		this.autor_id = autor_id;
	}

	public Set<Book> getBooks() {
		return books;
	}

	public void setBooks(Set<Book> books) {
		this.books = books;
	}
}
